$("#todayLoginButton").on('click',function(){
    $("#todayLoginChart").fadeIn();
    $("#webFluxsDiv").css({'width': '650px','float': 'left','margin-top': '0px'});
});
    	
$("#todayLoginHideButton").on('click',function(){
    $("#todayLoginChart").fadeOut();
    $("#webFluxsDiv").css({'width': '650px','float': 'left','margin-top': '-140px'});
});

$("#loginNumRefresh").on('click',function(){
	getTodayLoginNum();
});

$("#onlineNumRefresh").on('click',function(){
	getOnineNum();
});

$("#authRefresh").on('click',function(){
	authChart();
});

$("#temRefresh").on('click',function(){
	temChart();
});

$("#todayLoginRefresh").on('click',function(){
	getTodayLoginNumChart();
});

$("#todayLoginChartDiv").on('click',function(){
	getWebFluxChart();
});

$(function(){
	getTodayLoginNum();
	getOnineNum();
	getTodayLoginNumChart();
	temChart();
	getWebFluxChart();
	authChart();
    //自动刷新
	t=setInterval("autoMainRefresh()",600000);//自动刷新 10分钟刷新一次
});	
    	
//自动刷新方法
function autoMainRefresh(){
	//获取当日认证数
	getTodayLoginNum();
	
	//获取当前在线人数
	getOnineNum();
	
	//当月认证数折线图
	getTodayLoginNumChart();
	
	//认证终端饼图
	temChart();
	
	//平台流量
	getWebFluxChart();
	
	//认证方式饼图
	authChart();
	
}

function getTodayLoginNum(){
//获取当日认证数
	$.ajax({
		type:"POST",
		url:$(path).val()+"/analysis/OnlineNumberManage/getTodayLoginNum.do",
		async: false,
		cache: false,
		success: function(data){
			var errorMsg = eval("("+data+")");
			var status = errorMsg.status;
			var msg = errorMsg.msg;
			if(status){
				$("#todayLoginNum").html(msg);
			}else{
				swal(msg);
			}
		},
		error: function(data){
			swal("系统异常,请联系系统管理员!", "", "error");
		}
	});
}
	
function getOnineNum(){
	//获取当前在线人数
	$.ajax({
		type:"POST",
		url:$(path).val()+"/analysis/OnlineNumberManage/getOnineNum.do",
		async: false,
		cache: false,
		success: function(data){
			var errorMsg = eval("("+data+")");
			var status = errorMsg.status;
			var msg = errorMsg.msg;
			if(status){
				$("#todayOnlineNum").html(msg);
			}else{
				swal(msg);
			}
		},
		error: function(data){
			swal("系统异常,请联系系统管理员!", "", "error");
		}
	});	
}

//图表模块
//----当日认证数------------------------------------------------------------------------------------------------------------------
function getTodayLoginNumChart(){
	
	var todayLoginNumChart = echarts.init(document.getElementById('todayLoginChartDiv'), 'shine');
	//获取当日各时段认证人数
	$.ajax({
		type:"POST",
		url:$(path).val()+"/analysis/OnlineNumberManage/getTodayLoginDetail.do",
		async: false,
		cache: false,
		success: function(data){
			var errorMsg = eval("("+data+")");
			var data = errorMsg.data;
			var XaisName = [];
			var values = [];
			for(var i=0;i<data.length;i++){
				XaisName.push(data[i].time);
				values.push(data[i].count);
			}
			todayLoginOption.series[0].data=values;
			todayLoginOption.xAxis.data=XaisName;
			todayLoginNumChart.setOption(todayLoginOption);
		},
		error: function(data){
			swal("系统异常,请联系系统管理员!", "", "error");
		}
	});	
}

var todayLoginOption = {
		    title: {
		        text: ''
		    },
		    tooltip : {
		        trigger: 'axis'
		    },
		    legend: {
		        data:['认证人数']
		    },
		    toolbox: {
		        feature: {
		            saveAsImage: {}
		        }
		    },
		    grid: {
		        left: '3%',
		        right: '4%',
		        bottom: '3%',
		        containLabel: true
		    },
		    xAxis :{
		            type : 'category',
		            boundaryGap : false,
		            data : []
		    },
		    yAxis : {
		            type : 'value'
		    },
		    series : [
		        {
		            name:'认证人数',
		            type:'line',
		            stack: '总量',
		            areaStyle: {normal: {}},
		            data:[]
		        }
		    ]
		};


//----终端饼图------------------------------------------------------------------------------------------------------------------
function temChart(){
	var temNumChart = echarts.init(document.getElementById('temDiv'));
	
	$.ajax({
		type:"POST",
		url:$(path).val()+"/analysis/dogTerminalManage/getTerminalByTime.do",
		async: false,
		cache: false,
		success: function(data){
			var errorMsg = eval("("+data+")");
			var data = errorMsg.data;
			var legendName = [];
			var values = [];
			for(var i=0;i<data.length;i++){
				legendName.push(data[i].name);
				values.push(data[i]);
			}
			temOption.series[0].data=values;
			temOption.legend.data=legendName;
			temNumChart.setOption(temOption);
		},
		error: function(data){
			swal("系统异常,请联系系统管理员!", "", "error");
		}
	});	
}

var temOption = {
	    title : {
	        text: '',
	        subtext: '',
	        x:'center'
	    },
	    tooltip : {
	        trigger: 'item',
	        formatter: "{a} <br/>{b} : {c} ({d}%)"
	    },
	    legend: {
	        x : 'center',
	        y : 'center',
	        data:[]
	    },
	    calculable : true,
	    series : [
	        {
	            name:'终端类型',
	            type:'pie',
	            radius : [10, 40],
	            center : ['50%', '20%'],
	            roseType : 'area',
	            data:[
	               
	            ]
	        }
	    ]
	};
//----认证饼图------------------------------------------------------------------------------------------------------------------
function authChart(){
	var authNumChart = echarts.init(document.getElementById('authDiv'));
	
	$.ajax({
		type:"POST",
		url:$(path).val()+"/analysis/AuthentTypeNumManage/getAuthTypeByTime.do",
		async: false,
		cache: false,
		success: function(data){
			var errorMsg = eval("("+data+")");
			var data = errorMsg.data;
			var legendName = [];
			var values = [];
			for(var i=0;i<data.length;i++){
				legendName.push(data[i].name);
				values.push(data[i]);
			}
			authOption.series[0].data=values;
			authOption.legend.data=legendName;
			authNumChart.setOption(authOption);
		},
		error: function(data){
			swal("系统异常,请联系系统管理员!", "", "error");
		}
	});	
}

var authOption = {
	    title : {
	        text: '',
	        subtext: '',
	        x:'center'
	    },
	    tooltip : {
	        trigger: 'item',
	        formatter: "{a} <br/>{b} : {c} ({d}%)"
	    },
	    legend: {
	        x : 'center',
	        y : 'center',
	        data:[]
	    },
	    calculable : true,
	    series : [
	        {
	            name:'',
	            type:'pie',
	            radius : [10, 35],
	            center : ['50%', '18%'],
	            roseType : 'area',
	            data:[]
	        }
	    ]
	};


//---------平台流量-------------------------------------------------------------------------------------------------------------
function getWebFluxChart(){
	var webFluxChart = echarts.init(document.getElementById('webFluxChartDiv'));
	//获取当日各时段认证人数
	$.ajax({
		type:"POST",
		url:$(path).val()+"/monitor/getWebFluxHour.do",
		async: false,
		cache: false,
		success: function(data){
			var errorMsg = eval("("+data+")");
			var data = errorMsg.data;
			var XaisName = [];
			var values = [];
			for(var i=0;i<data.length;i++){
				XaisName.push(data[i].time);
				values.push(data[i].fluxs);
			}
			webFluxOption.series[0].data=values;
			webFluxOption.xAxis.data=XaisName;
			webFluxChart.setOption(webFluxOption);
		},
		error: function(data){
			swal("系统异常,请联系系统管理员!", "", "error");
		}
	});	
}


var webFluxOption = {
	    title: {
	        text: ''
	    },
	    tooltip : {
	        trigger: 'axis'
	    },
	    legend: {
	        data:['平台流量']
	    },
	    toolbox: {
	        feature: {
	            saveAsImage: {}
	        }
	    },
	    grid: {
	        left: '3%',
	        right: '4%',
	        bottom: '3%',
	        containLabel: true
	    },
	    xAxis :{
	            type : 'category',
	            boundaryGap : false,
	            data : []
	    },
	    yAxis : {
	            type : 'value'
	    },
	    series : [
	        {
	            name:'平台流量',
	            type:'line',
	            stack: '总量',
	            areaStyle: {normal: {}},
	            data:[]
	        }
	    ]
	};
//----------------------------------------------------------------------------------------------------------------------
